# 斐波那契数列
def fib(n):
    if n < 2:
        return n
    else:
        return fib(n - 2) + fib(n - 1)


print(fib(7))


# 快排
def quick(qlist):
    if len(qlist) == 0:
        return qlist
    else:
        qb = qlist[0]
        qa = quick([m for m in qlist[1:] if m <= qb])
        qc = quick([l for l in qlist[1:] if l > qb])
        return qa + [qb] + qc


print(quick([23, 5, 32, 1, 52]))


# 随机插入排序
def insertQuick(qlist):
    for i in range(len(qlist)):
        key = qlist[i]
        j = i -1
        while j >= 0 and key < qlist[j]:
            qlist[j + 1] = qlist[j]
            j -= 1
            qlist[j + 1] = key
    return qlist

print(insertQuick([23, 5, 32, 1, 52]))

# 99乘法表
def n_n():
    for i in range(1, 10):
        for j in range(1, i + 1):
            print(f'{j}*{i}={j*i}', end=' ')
        print('\t')


print(n_n())

# 统计字符串中出现次数最多的字符和次数
def countStr():
    str1 = "asidjasidwessssrfwe"
    d1 = {}
    for s in str1:
        if s not in d1:
            d1[s] = 1
        else:
            d1[s] += 1

    for k, v in d1.items():
        if v == max(d1.values()):
            print(k, v)

countStr()

# Switch语句
def sw():
    switch = {
        "s1": "我入职啦",
        "s2": "开始工作了",
        "s3": "挣钱了",
        "s4": "薪酬打仗",
        "s5": ["成功", 123, {'ok'}]
    }
    return switch['s1']


print(sw())


# filter()筛选功能
def name(n):
    if n.startswith('张'):
        return True
print(list(filter(name, ['张章', '薛薛', '王王'])))

# map()映射方法
def 加法(i):
    i = i **3
    return i

print(list(map(加法, [23, 2, 4, 14])))

# 获取list索引位置
def lindex():
    list1 = [2, 3, 4, 52, 11]
    print(list1.index(11))


print(lindex())

# 判断字符串中大写的几个，小写的几个
def bs():
    str1 = "asdADASDAdasdDAAAA123"
    small = 0
    big = 0
    other = 0
    for s in str1:
        if s.islower():
            small += 1
        elif s.isupper():
            big += 1
        else:
            other += 1
    print(f'small:{small},big:{big}, other:{other}')


print(bs())


# 修改元组内部元素不可修改的元素

# 列表推导式
print([l for l in range(10)])

# 集合推导式
print({l for l in range(10)})
# 字典推导式
list2 = [2, 3, 4, 5, 6, 77]
print({i:list2[i] for i in range(len(list2))})
# 函数嵌套

# 迭代器
list3 = [33, 44, 55, 66]
l3 = list3.__iter__()
print(l3.__next__())
print(l3.__next__())
print(l3.__next__())
print(next(l3))
# 生成器
def generatorr():
    list1 = [2, 3, 4, 5]
    list2 = [11]
    yield list1 + list2
    list3 = [3]
    yield list1.append(list3)

g1 = generatorr()
print(g1.__iter__())
print(g1.__next__())
print(g1.__next__())


# 装饰器
def wapper(name):
    """


    :param name: 目标函数
    :return:
    """
    i = 'abc'
    def inner(*args, **kwargs):
        nonlocal i
        i = "aabbcc"
        print(i)
        rname = name(*args, **kwargs)
        print(args, kwargs)
        print(rname)
        return rname
    return inner

@wapper  # game = wapper(game)
def game(username, password):
    print(f'game函数打印：{username}:{password}')
    return "游戏开始"

game("zkk", "admin123456")